package communication.common.command;

import communication.common.business.util.OsParamUtil;
import io.vertx.core.cli.Argument;
import io.vertx.core.cli.CLI;
import io.vertx.core.cli.CommandLine;
import io.vertx.core.cli.Option;
import io.vertx.ext.shell.command.CommandBuilder;
import org.springframework.stereotype.Component;


/**
 *  用来 打印mac地址的cli
 * @author mac
 */
@Component
public class MacAddressCli implements BaseCommandCli{

    @Override
    public CommandBuilder getCliBuilder(){

        // 命令例子： mac -n en0 或者 mac -name en0 或者 mac --name en1
        CLI cli = CLI.create("mac")
                .addOption(new Option().setShortName("n").setLongName("name").setRequired(false));

        CommandBuilder commandBuilder=CommandBuilder.command(cli);
        commandBuilder.processHandler(process->{
            CommandLine commandLine = process.commandLine();
            String optionValues = commandLine.getOptionValue("n");
            process.write(OsParamUtil.getLocalMac(optionValues));
            process.end();
        });
        return commandBuilder;
    }

}
